import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import axios from 'axios'
import echarts from 'echarts'
import TreeTable from 'vue-table-with-tree-grid'
import { hasPermission } from './utils/permissionDirect'

const Plugins = [hasPermission]
Plugins.map((plugin) => {
    Vue.use(plugin)
})

Vue.use(TreeTable)

NProgress.configure({ease: 'ease', speed: 500});
NProgress.configure({minimum: 0.3});
Vue.prototype.$http = axios
Vue.prototype.$echarts = echarts

axios.defaults.baseURL = 'http://www.localhost:8081/'


//请求拦截器
axios.interceptors.request.use(config => {
  NProgress.start()
  config.headers.Authorization = LocalStorage.get(LOCAL_KEY_ACCESS_TOKEN);
  return config;
}
, error => {
  return Promise.reject(error)
});

//响应拦截器
axios.interceptors.response.use(
function (response) {
  NProgress.done();
  const res = response.data;
  if (res.success) {
      return response;
  }

  if (res.data!=null&&res.data.errorCode === 50001) {
      LocalStorage.clearAll();
      return router.push("/login");
  }
  return response;
},
function (error) {
  return Promise.reject(error)
}
)


Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
